<template>
  <div class="count-card">
    <div class="card-head">
      <h1>{{ detailInfo.title }}</h1>
      <div
        :class="[
          'totalInfo',
          numInfo[0] === 1 ? 'warning' : numInfo[0] === 2 ? 'error' : '',
        ]"
      >
        {{ numInfo[1] }}
      </div>
    </div>
    <div class="card-content">
      <div class="left-content">
        <h2>{{ detailInfo.total }}</h2>
        <span>使用上限</span>
      </div>
      <div class="right-content">
        <h2>{{ detailInfo.used }}</h2>
        <span>累计使用</span>
      </div>
    </div>
    <el-progress :percentage="numInfo[2]" color="#658BFC" :show-text="false"></el-progress>
  </div>
</template>

<script>
export default {
  name: "CountCard",
  props: ["detailInfo"],
  computed: {
    numInfo() {
      if (this.detailInfo.total === "无限制") {
        return [0, "", 0];
      }
      let percent = parseFloat(this.detailInfo.used) / parseFloat(this.detailInfo.total);
      if (percent <= 0.8) {
        return [0, "", percent * 100];
      } else if (percent > 0.8 && percent <= 0.95) {
        return [1, "容量不足", percent * 100];
      } else {
        return [2, "容量已用完", percent * 100];
      }
    },
  },
};
</script>

<style lang="less" scoped>
.count-card {
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  background-color: #fff;
  .card-head {
    padding: 14px 22px;
    border-bottom: 1px solid #e8eaed;
    display: flex;
    justify-content: space-between;
    align-items: center;
    h1 {
      color: #1f2329;
      font-size: 16px;
      font-weight: 400;
    }
    .totalInfo {
      font-size: 12px;
      &.warning {
        color: #ff9801;
        background-color: #fff6e5;
      }
      &.error {
        color: #ff6459;
        background-color: #fff0ef;
      }
    }
  }
  .card-content {
    display: flex;
    justify-content: space-between;
    padding: 30px 22px;
    & > * {
      display: flex;
      flex-direction: column;
    }
    h2 {
      font-weight: 500;
      font-size: 28;
      line-height: 42px;
    }
    .left-content {
      justify-content: flex-start;
      h2 {
          color: #1f2329;
      }
    }
    .right-content {
      justify-content: flex-end;
      h2 {
          color: #4c78fc;
      }
    }
  }
}
</style>